package com.hoyin.viewtest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.hoyin.viewtest.dependencies.ListItem;
import com.hoyin.viewtest.dependencies.RecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity {
	private List<ListItem> listItems = new ArrayList<>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_recycler_view);
		initItems(listItems);
		RecyclerView recyclerView = findViewById(R.id.recyclerView);                //recyclerView是针对垂直列表的尝试
		RecyclerView recyclerView_hori = findViewById(R.id.recyclerView_horizontal);//recyclerView_hori是针对水平列表的尝试
		LinearLayoutManager layoutManager = new LinearLayoutManager(this);  //默认的layoutManagerOrientation为VERTICAL
		layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);               //所以水平列表要进行setOrientation
		recyclerView.setLayoutManager(new LinearLayoutManager(this));       //垂直列表直接使用匿名对象
		recyclerView_hori.setLayoutManager(layoutManager);                          //将LayoutManager绑定到水平列表
		RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(listItems);//此处公用一个Adapter
		recyclerView.setAdapter(recyclerViewAdapter);
		recyclerView_hori.setAdapter(recyclerViewAdapter);
	}

	private void initItems(List<ListItem> listItems) {
		for (int i = 0; i < 10; i++) {
			listItems.add(new ListItem("Item" + i, R.drawable.list_item_image));
		}
	}
}